package kr.saeildamil.androidstudy.ch17;

import java.io.File;

import kr.saeildamil.androidstudy.R;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Toast;

public class CallOther extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch17_callother);
	}
	
	public void mOnClick(View v){
		Intent intent;
		switch(v.getId()){
		case R.id.ch17_calloter_btn01:
			intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.naver.com"));
			startActivity(intent);
			break;
		case R.id.ch17_calloter_btn02:
			intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:015-123-1234"));
			startActivity(intent);
			break;
		case R.id.ch17_calloter_btn03:
			String sdPath = Environment.getExternalStorageDirectory().getAbsolutePath();
			File file = new File(sdPath+"/korandoc.jpg");
			Uri uri = Uri.fromFile(file);
			intent = new Intent(Intent.ACTION_VIEW, uri);
			intent.setDataAndType(uri, "image/jpeg");
			startActivity(intent);
			break;
		case R.id.ch17_calloter_btn04:
			intent = new Intent(Intent.ACTION_MAIN);
			intent.setComponent(new ComponentName("com.example.otherapp", "com.example.otherapp.MainActivity"));
			//intent.setClassName("com.example.otherapp", "com.example.otherapp.MainActivity");
			startActivity(intent);
			break;
		case R.id.ch17_calloter_btn05:
			intent = new Intent(Intent.ACTION_MAIN);
			intent.setClassName("kr.co.saeildamil.calc", "kr.co.saeildamil.calc.MainActivity");
			intent.putExtra("left", 3);
			intent.putExtra("right", 4);
			startActivity(intent);
			break;
		case R.id.ch17_calloter_btn06:
			try{
				intent = new Intent("kr.co.saeildamil.mul.MUL");
				intent.putExtra("mLeft", 3);
				intent.putExtra("mRight", 4);
				startActivity(intent);
			}catch(ActivityNotFoundException e){
				Toast.makeText(this, "해당 패키지가 설치 안됨", Toast.LENGTH_SHORT).show();
			}
			
			break;
		}
	}
}
